package gui;

import engine.LDAPManager;
import engine.OntologyBuilder;
import java.util.logging.Level;
import java.util.logging.Logger;
import org.apache.commons.cli.CommandLine;
import org.apache.commons.cli.CommandLineParser;
import org.apache.commons.cli.HelpFormatter;
import org.apache.commons.cli.Option;
import org.apache.commons.cli.Options;
import org.apache.commons.cli.ParseException;
import org.apache.commons.cli.PosixParser;

/**
 *
 * @author Pospishnyi Oleksandr
 */
public class Glue2Import {

    public static void main(String[] args) {
        Options options = new Options();
        options.addOption(new Option("tbox", true, "GLUE2 TBox Ontology file"));
        options.addOption(new Option("abox", true, "Output ontology file"));
        options.addOption(new Option("iri", true, "Ontology IRI"));
        options.addOption(new Option("server", true, "LDAP server IP"));
        options.addOption(new Option("port", true, "LDAP server port"));

        if (args.length != 10) {
            HelpFormatter formatter = new HelpFormatter();
            formatter.printHelp("Glue2Import", options, true);
            return;
        }

        CommandLineParser clp = new PosixParser();
        try {
            CommandLine cline = clp.parse(options, args);

            LDAPManager ldapm = new LDAPManager(cline.getOptionValue("server"), cline.getOptionValue("port"));
            OntologyBuilder ontologyBuilder =
                    new OntologyBuilder(cline.getOptionValue("tbox"),
                    cline.getOptionValue("abox"), cline.getOptionValue("iri"));
            ontologyBuilder.createNewEmptyOntology();
            ontologyBuilder.populate(ldapm.retrive("Glue2Entity"));
            ontologyBuilder.flush();
            ldapm.close();
        } catch (Exception ex) {
            Logger.getLogger(Glue2Import.class.getName()).log(Level.SEVERE, null, ex);
        }

    }
}
